/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * oneBrokerPanel.java
 *
 * Created on 08-Sep-2009, 23:15:09
 */

package com.gemom.gui;


import com.gemom.*;
import com.gemom.util.*;
import com.gemom.combinationItems.*;

import java.util.*;

/**
 *
 * @author Yair D
 */
public class oneBrokerPanel extends javax.swing.JPanel {

    /** Creates new form oneBrokerPanel */
    public oneBrokerPanel(int brID,CovMatrixData covM,Item[] arrayItems) {

        this.id=brID;
         this.covM=covM;
         this.itemsArray=arrayItems;
        initComponents();

        this.setBorder(javax.swing.BorderFactory.createTitledBorder("Broker"+brID));
        this.jButton2bids.setEnabled(false);
        this.jButton1capOK.setEnabled(true); 
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel2 = new javax.swing.JLabel();
        jTextField1capOK = new javax.swing.JTextField("70");
        jButton1capOK = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jButton2bids = new javax.swing.JButton();

        setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        jLabel2.setText("Capacity");

        jTextField1capOK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField1capOKActionPerformed(evt);
            }
        });

        jButton1capOK.setText("OK");
        jButton1capOK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1capOKActionPerformed(evt);
            }
        });

        jTextArea1.setColumns(20);
        jTextArea1.setEditable(false);
        jTextArea1.setRows(5);
        jScrollPane1.setViewportView(jTextArea1);

        jButton2bids.setText("Generate Bids");
        jButton2bids.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2bidsActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 165, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 54, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField1capOK, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1capOK)
                        .addGap(23, 23, 23))
                    .addComponent(jButton2bids, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 165, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTextField1capOK, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1capOK))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton2bids)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(29, 29, 29))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jTextField1capOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1capOKActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField1capOKActionPerformed

    private void jButton1capOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1capOKActionPerformed
        // TODO add your handling code here:
         this.jButton2bids.setEnabled(true);
         this.jButton1capOK.setEnabled(false);
        
         this.brcap=Double.parseDouble(this.jTextField1capOK.getText());////////////
         this.broker= new GBroker(id,Double.parseDouble(this.jTextField1capOK.getText()));
         
    }//GEN-LAST:event_jButton1capOKActionPerformed

    private void jButton2bidsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2bidsActionPerformed
        // TODO add your handling code here:

        BidG bidg = new BidG(itemsArray,covM,this.broker);
        listBids= bidg.getlistBids();
        for(int i=0;i<listBids.size();i++)
            this.jTextArea1.append("Bid"+listBids.get(i).getBidID()+": ("
                    +listBids.get(i)+")\n");
        this.jButton2bids.setEnabled(false);
       
    }//GEN-LAST:event_jButton2bidsActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1capOK;
    private javax.swing.JButton jButton2bids;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextField jTextField1capOK;
    // End of variables declaration//GEN-END:variables
    private double brcap=70;

    private GBroker broker;
    private int id=0;
    CovMatrixData covM;
    private Item[] itemsArray;
    private Vector<Bid> listBids;



    public double getBrCap(){return this.brcap;}////////
    public GBroker getBroker(){return this.broker;}
    public  Vector<Bid> getlistBids(){return listBids;}

}

